<?php
class PointsController extends AppController
{
	//var $scaffold;
	var $name = 'Points';
var $helpers = array('GoogleMapV3'); 

	function index() {

		$this->Point->recursive = 0;
		$this->set('points', $this->Point->find('all'));
		//$this->set('points', $this->paginate());
	}

	function add() {
		if(empty($this->data)) {
			$this->render();
		} else {
			$this->cleanUpFields();
			
			$address = $this->data['Point'];
			unset(
				$address['name'],$address['description'],
				$address['latitude'], $address['longitude'],
				$address['zoom']
				);
			var_dump($address);
			vendor('googlegeo');
			$googleGeo = new GoogleGeo($address);
			$geo = $googleGeo->geo();
			var_dump($geo);
			$this->data = array_merge($this->data['Point'],$geo);
			
			if($this->Point->save($this->data)) {
				$this->Session->setFlash('The Point has been saved');
				//$this->redirect('/points/index');
			} else {
				$this->Session->setFlash('Please correct errors below.');
			}
		}
	}

	function edit($id) {
		if(empty($this->data)) {
			$this->data = $this->Point->read(null, $id);
		} else {
			$this->cleanUpFields();
			
			$address = $this->data;
			unset(
				$this->data['name'],$this->data['description'],
				$this->data['latitude'], $this->data['longitude'],
				$this->data['zoom']
				);
			vendor('googlegeo');
			$googleGeo = new GoogleGeo($address);
			$geo = $googleGeo->geo();
			$this->data = array_merge($this->data,$geo);
			
			if($this->Point->save($this->data)) {
				$this->Session->setFlash('The Point has been saved');
				$this->redirect('/points/index');
			} else {
				$this->Session->setFlash('Please correct errors below.');
			}
		}
	}
/*
	function view($id) {
		$this->layout = "map";
		$this->set('point', $this->Point->read(null, $id));
	}

	function delete($id) {
		if($this->Point->del($id)) {
			$this->Session->setFlash('The Point deleted: id '.$id.'');
			$this->redirect('/points/index');
		}
	}
*/
}
?>
